/**
 * Project: apollo-base-tools
 * 
 * File Created at 2017年8月2日
 * 
 * Copyright 2015-2016 dx.com Croporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * DongXue software Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with dx.com.
 */
package org.apollo.base.tools.ui;

import java.awt.event.ActionEvent;

import javax.swing.Icon;

import org.apollo.base.tools.ui.action.BaseAction;
import org.apollo.base.tools.ui.constants.UIConstants;
import org.apollo.base.tools.ui.panel.BaseJPanel;
import org.apollo.base.tools.ui.panel.FileComparePanel;
import org.apollo.base.tools.ui.panel.HomePanel;
import org.apollo.base.tools.ui.view.JAccordionPanel;
import org.apollo.base.tools.ui.view.JDynamicTabbedPane;
import org.apollo.base.tools.ui.view.JListLabelPanel;
import org.apollo.base.tools.ui.view.LinkLabel;

/**
 * @ClassName: TabbedManager
 * @Description: 菜单管理器
 * @author wuzhenfang(wzfbj2008@163.com)
 * @date 2017年8月2日 上午10:02:29
 * @version V1.0
 */
public class MenuManager {

	private JDynamicTabbedPane tabbedPane;

	private JAccordionPanel accordionPanel;

	private JListLabelPanel toolsListPanel;//
	private JListLabelPanel codeGenListPanel;//

	public void init() {
		getTabbedPane().addTab(UIConstants.firstTabTitle, UIConstants.ICON_HOME, new HomePanel(), "首页", false);
		loadMenu();// 加载菜单
		getAccordionPanel().setAnimated(true);
	}

	public void loadMenu() {
		/** 一级菜单 **/
		addLevel1Menu("我的工具", UIConstants.ICON_03, getToolsListPanel());
		addLevel1Menu("代码生成器", UIConstants.ICON_03, getCodeGenListPanel());
		/** 2.1级菜单 **/
		addLevel2Menu("文件比较", UIConstants.ICON_demo, getToolsListPanel(), new FileComparePanel(), true);
		addLevel2Menu("批量删除文件", UIConstants.ICON_demo, getToolsListPanel(), new BaseJPanel(), true);
		addLevel2Menu("生成代码", UIConstants.ICON_GEN, getToolsListPanel(), new BaseJPanel(), true);
		
		// /** 2.1级菜单 **/
		// addLevel2Menu("添加数据库", UIConstants.ICON_demo, getCodeGenListPanel(), new BaseJPanel(), true);
		// addLevel2Menu("生成工程代码", UIConstants.ICON_GEN, getCodeGenListPanel(), new BaseJPanel(), true);
	}

	/**
	 * 添加一级菜单
	 * @param title
	 * @param icon
	 * @param listpanel
	 */
	public void addLevel1Menu(String title, Icon icon, JListLabelPanel listpanel) {
		getAccordionPanel().addItemPanel(title, icon, listpanel);
	}

	/**
	 * 添加二级菜单
	 * @param title
	 * @param icon
	 * @param listpanel
	 * @param panel
	 * @param closable
	 */
	public void addLevel2Menu(String title, Icon icon, JListLabelPanel listpanel, BaseJPanel panel, boolean closable) {
		listpanel.addItem(title, icon, new BaseAction() {
			@Override
			public void actionPerformed(ActionEvent event) {
				getTabbedPane().addTab(title, icon, panel, title, closable);
			}
		});
		listpanel.setSize(185, 74);
	}

	private JListLabelPanel getToolsListPanel() {
		if (toolsListPanel == null) {
			toolsListPanel = new JListLabelPanel();
		}
		return toolsListPanel;
	}

	private JListLabelPanel getCodeGenListPanel() {
		if (codeGenListPanel == null) {
			codeGenListPanel = new JListLabelPanel();

		}
		return codeGenListPanel;
	}

	/**
	 * @return the tabbedPane
	 */
	public JDynamicTabbedPane getTabbedPane() {
		return tabbedPane;
	}

	/**
	 * @return the accordionPanel
	 */
	public JAccordionPanel getAccordionPanel() {
		return accordionPanel;
	}

	/**
	 * @param tabbedPane the tabbedPane to set
	 */
	public void setTabbedPane(JDynamicTabbedPane tabbedPane) {
		this.tabbedPane = tabbedPane;
	}

	/**
	 * @param accordionPanel the accordionPanel to set
	 */
	public void setAccordionPanel(JAccordionPanel accordionPanel) {
		this.accordionPanel = accordionPanel;
	}

}
